<?php
namespace SimpleMVC\lib;

use SimpleMVC\SimpleMVC;

class Dao {
	
	private static $connections = array();
	
	/**
	 * 获取数据库连接
	 * @param string $name
	 * @return PdoConnection
	 */
	public static function getConnection($name = 'default')
	{
		if (!isset(self::$connections[$name]))
		{
			$config = SimpleMVC::getConfig();
			if (isset($config['db'][$name]) && isset($config['db'][$name]['dsn']) && isset($config['db'][$name]['user']) && isset($config['db'][$name]['password'])) {
				self::$connections[$name] = new PdoConnection($config['db'][$name]['dsn'], $config['db'][$name]['user'], $config['db'][$name]['password']);
			} else {
				self::$connections[$name] = null;
			}
		}
		return self::$connections[$name];
	}
}